package com.lxk.vo.result;

/**
 * @author JohnSoybean
 * @create 2020/3/19 15:57
 * @description 返回结果通用实体类
 */
public class Result<T> {
    private Integer code; //返回代码
    private String msg; //返回信息
    private T data;//返回实体

    private Result(CodeMsg codeMsg){
        if(codeMsg!=null) {
            this.code = codeMsg.getCode();
            this.msg = codeMsg.getMsg();
            this.data=null;
        }
    }

    private Result(T data){
        this.code=0;
        this.msg="success";
        this.data=data;
    }

    public static <T> Result<T> success(T data){
        return new Result<T> (data);
    }

    public static <T> Result<T> error(CodeMsg codeMsg){

        return new Result<T>(codeMsg);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
